package com.imooc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.imooc.mapper.LoganMapper;
import com.imooc.mapper.LoganMapperCustom;
import com.imooc.pojo.Logan;
import com.imooc.service.LoganService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class LoganServiceImpl implements LoganService {
    @Autowired
    private LoganMapper loganMapper;

    @Autowired
    private LoganMapperCustom loganMapperCustom;

    @Transactional(propagation = Propagation.REQUIRED)
    public long insertIntoLogan(List<Logan> list) {
        int result = loganMapper.insertList(list);
        return result;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public List<Logan> queryLoganList(int f) {
        List<Logan> loganList = loganMapperCustom.queryLoganInfoList(f);
        return loganList;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public PageInfo<Logan> queryLoganList(int page,int pageSize) {
        PageHelper.startPage(page, pageSize);//添加分页查询器
        List<Logan> loganList = loganMapper.selectAll();
        PageInfo<Logan> pi = new PageInfo<>(loganList);
        return pi;
    }
}
